package com.tmc.web.controller.intcar;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tmc.bean.common.CommonResult;
import com.tmc.bean.common.ContextInfo;
import com.tmc.bean.intcar.EthAdditionalService;
import com.tmc.bean.intcar.EthCancelOrderReq;
import com.tmc.bean.intcar.EthConfirmOrderReq;
import com.tmc.bean.intcar.EthDriver;
import com.tmc.bean.intcar.EthOrderFinishedReq;
import com.tmc.bean.intcar.EthPassenger;
import com.tmc.bean.intcar.EthPushDriverReq;
import com.tmc.bean.intcar.EthQueryDriverReq;
import com.tmc.bean.intcar.EthQueryPriceReq;
import com.tmc.bean.intcar.EthSubmitOrderReq;
import com.tmc.bean.intcar.EthUpdateOrderReq;
import com.tmc.service.intcar.IntcarCancelOrderServiceImpl;
import com.tmc.service.intcar.IntcarConfirmOrderServiceImpl;
import com.tmc.service.intcar.IntcarOrderFinishedServiceImpl;
import com.tmc.service.intcar.IntcarPushDriverServiceImpl;
import com.tmc.service.intcar.IntcarQueryDriverServiceImpl;
import com.tmc.service.intcar.IntcarQueryPriceServiceImpl;
import com.tmc.service.intcar.IntcarSubmitOrderServiceImpl;
import com.tmc.service.intcar.IntcarUpdateOrderServiceImpl;
import com.tmc.util.DateUtil;
import com.tmc.util.ObjectUtil;
import com.tmc.web.BaseController;

/**
 * 
 * @author zhang
 * @date 2018年1月12日 下午2:55:51
 */
@Controller
@RequestMapping("/api/intcar")
public class IntcarApiController extends BaseController{
	
	private Log log = LogFactory.getLog(this.getClass());

	@Autowired
	private IntcarQueryPriceServiceImpl queryPriceService;
	
	@Autowired
	private IntcarSubmitOrderServiceImpl submitOrderService;
	
	@Autowired
	private IntcarCancelOrderServiceImpl cancelOrderService;
	
	@Autowired
	private IntcarUpdateOrderServiceImpl updateOrderService;
	
	@Autowired
	private IntcarQueryDriverServiceImpl queryDriverService;
	
	@Autowired
	private IntcarConfirmOrderServiceImpl confirmOrderService;
	
	@Autowired
	private IntcarPushDriverServiceImpl pushDriverService;
	
	@Autowired
	private IntcarOrderFinishedServiceImpl orderFinishedService;
	
	
	/**
	 * 价格查询接口
	 * @author zhang
	 * 
	 * @param request
	 * @param useTime
	 * @param useDuration
	 * @param productType
	 * @param routeType
	 * @param carType
	 * @param staffNum
	 * @param luggageNum
	 * @param carCount
	 * @param airportCode
	 * @param fromCityID
	 * @param fromCityName
	 * @param fromAddress
	 * @param fromLongitude
	 * @param fromLatitude
	 * @param toCityID
	 * @param toCityName
	 * @param toAddress
	 * @param toLongitude
	 * @param toLatitude
	 * @param estimatedDistance
	 * @param estimatedTime
	 * @return
	 */
	@RequestMapping(value = "/queryPrice",  produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String queryPrice(HttpServletRequest request,
							 @RequestParam(required = false, value = "useTime")String useTime,
							 @RequestParam(required = false, value = "useDuration", defaultValue = "1")Integer useDuration,
							 @RequestParam(required = false, value = "productType")Integer productType,
							 @RequestParam(required = false, value = "routeType", defaultValue = "1")Integer routeType,
							 @RequestParam(required = false, value = "carType")String carType,
							 @RequestParam(required = false, value = "staffNum")Integer staffNum,
							 @RequestParam(required = false, value = "luggageNum")Integer luggageNum,
							 @RequestParam(required = false, value = "carCount", defaultValue = "1")Integer carCount,
							 @RequestParam(required = false, value = "airportCode")String airportCode,
							 @RequestParam(required = false, value = "flightNum")String flightNum,
							 @RequestParam(required = false, value = "fromCityCode")String fromCityCode,
							 @RequestParam(required = false, value = "fromCityID", defaultValue = "0")Integer fromCityID,
							 @RequestParam(required = false, value = "fromCityName")String fromCityName,
							 @RequestParam(required = false, value = "fromAddress")String fromAddress,
							 @RequestParam(required = false, value = "fromLongitude")Double fromLongitude,
							 @RequestParam(required = false, value = "fromLatitude")Double fromLatitude,
							 @RequestParam(required = false, value = "toCityCode")String toCityCode,
							 @RequestParam(required = false, value = "toCityID", defaultValue = "0")Integer toCityID,
							 @RequestParam(required = false, value = "toCityName")String toCityName,
							 @RequestParam(required = false, value = "toAddress")String toAddress,
							 @RequestParam(required = false, value = "toLongitude")Double toLongitude,
							 @RequestParam(required = false, value = "toLatitude")Double toLatitude,
							 @RequestParam(required = false, value = "estimatedDistance")Integer estimatedDistance,
							 @RequestParam(required = false, value = "estimatedTime")Integer estimatedTime){
		
			EthQueryPriceReq req = new EthQueryPriceReq();
			req.setUseTime(useTime);
			req.setUseDuration(useDuration);
			req.setProductType(productType);
			req.setRouteType(routeType);
			req.setCarType(carType);
			req.setStaffNum(staffNum);
			req.setLuggageNum(luggageNum);
			req.setCarCount(carCount);
			if(ObjectUtil.hasText(airportCode)){
				req.setAirportCode(airportCode.toUpperCase());
			}
			if(ObjectUtil.hasText(flightNum)){
				req.setFlightNum(flightNum.toUpperCase());
			}
			if(ObjectUtil.hasText(fromCityCode)){
				req.setFromCityCode(fromCityCode.toUpperCase());
			}
			req.setFromCityCode(fromCityCode);
			req.setFromCityID(fromCityID);
			req.setFromCityName(fromCityName);
			req.setFromAddress(fromAddress);
			req.setFromLongitude(fromLongitude);
			req.setFromLatitude(fromLatitude);
			if(ObjectUtil.hasText(toCityCode)){
				req.setToCityCode(toCityCode.toUpperCase());
			}
			req.setToCityID(toCityID);
			req.setToCityName(toCityName);
			req.setToAddress(toAddress);
			req.setToLongitude(toLongitude);
			req.setToLatitude(toLatitude);
			req.setEstimatedDistance(estimatedDistance);
			req.setEstimatedTime(estimatedTime);
			
			CommonResult check = this.check(req);
			if(!check.isSuccess()){
				return check.toJson();
			}
		try {
			//ContextInfo context = this.getContextInfo(request);
			CommonResult result = queryPriceService.queryPrice(new ContextInfo(), req);
			return result.toJson();
		} catch (Exception e) {
			log.error("查询出错！", e);
		}
		return CommonResult.makeFail("查询出错").toJson();
	}
	
	/**
	 * 提交订单
	 * 
	 * @author zhang
	 * @return
	 */
	@RequestMapping(value = "/submitOrder" , produces = "text/xml;charset=UTF-8")
	@ResponseBody
	public String submitOrder(HttpServletRequest request, @RequestBody EthSubmitOrderReq submitOrderReq,
							  @RequestParam(required = false, value = "priceMark")String priceMark,
							  @RequestParam(required = false, value = "carTypeID")Integer carTypeID,
							  @RequestParam(required = false, value = "staffNum")Integer staffNum,
							  @RequestParam(required = false, value = "setAmount")Double setAmount,
							  @RequestParam(required = false, value = "totalAmount")Double totalAmount,
							  @RequestParam(required = false, value = "additionalServiceAmount")Double additionalServiceAmount,
							  @RequestParam(required = false, value = "luggageNum")Integer luggageNum,
							  @RequestParam(required = false, value = "name")String name,
							  @RequestParam(required = false, value = "areaCode")String areaCode,
							  @RequestParam(required = false, value = "phone")String phone,
							  @RequestParam(required = false, value = "overSeasAreaCode")String overSeasAreaCode,
							  @RequestParam(required = false, value = "overSeasPhone")String overSeasPhone,
							  @RequestParam(required = false, value = "age")Integer age,
							  @RequestParam(required = false, value = "cardType")Integer cardType,
							  @RequestParam(required = false, value = "cardNo")String cardNo,
							  @RequestParam(required = false, value = "gender")Integer gender,
							  @RequestParam(required = false, value = "email")String email,
							  @RequestParam(required = false, value = "wechat")String wechat
							  ){
		System.out.println(submitOrderReq);
		ContextInfo context = this.getContextInfo(request);
		EthSubmitOrderReq bookingReq = new EthSubmitOrderReq();
		bookingReq.setPriceMark(priceMark);
		bookingReq.setLuggageNum(luggageNum);
		bookingReq.setStaffNum(luggageNum);
		bookingReq.setCarTypeID(carTypeID);
		bookingReq.setTotalAmount(totalAmount);
		bookingReq.setSetAmount(setAmount);
		bookingReq.setAdditionalServiceAmount(additionalServiceAmount);
		
		EthPassenger passenger = new EthPassenger();
		passenger.setName(name);
		passenger.setAreaCode(areaCode);
		passenger.setPhone(phone);
		passenger.setOverSeasAreaCode(overSeasAreaCode);
		passenger.setOverSeasPhone(overSeasPhone);
		passenger.setAge(age);
		passenger.setCardType(cardType);
		passenger.setCardNo(cardNo);
		passenger.setGender(gender);
		passenger.setEmail(email);
		passenger.setWechat(wechat);
		
		List<EthPassenger> passengers = new ArrayList<EthPassenger>();
		passengers.add(passenger);
		bookingReq.setPassengers(passengers);
		
		CommonResult cr = this.check(bookingReq);
		if(!cr.isSuccess()){
			return cr.toJson();
		}
		try {
			CommonResult result = submitOrderService.booking(context, bookingReq);
			return result.toJson();
		} catch (Exception e) {
			log.error("系统错误！", e);
		}
		return CommonResult.makeFail("系统错误！").toJson();
	}
	
	/**
	 * 取消订单
	 * 
	 * @author zhang
	 * @param request
	 * @param orderID
	 * @param cancelTypeID
	 * @param cancelReason
	 * @return
	 */
	@RequestMapping(value = "/cancelOrder", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String cancelOrder(HttpServletRequest request,
							  @RequestParam(required=false, value="orderID")Long orderID,
							  @RequestParam(required=false, value="cancelTypeID", defaultValue="10")Integer cancelTypeID,
							  @RequestParam(required=false, value="cancelReason")String cancelReason){
		
		ContextInfo context = this.getContextInfo(request);
		EthCancelOrderReq req = new EthCancelOrderReq();
		req.setOrderID(orderID);
		req.setCancelTypeID(cancelTypeID);
		req.setCancelReason(cancelReason);
		
		CommonResult cr = this.check(req);
		if(!cr.isSuccess()){
			return cr.toJson();
		}
		
		try {
			CommonResult result= cancelOrderService.canceling(context, req);
			return result.toJson();
		} catch (Exception e) {
			log.error("系统错误！", e);
		}
		return CommonResult.makeFail("系统错误！").toJson();

	}
	
	/**
	 * 更新订单
	 * 
	 * @author zhang
	 * @param request
	 * @param passenger
	 * @param orderID
	 * @return
	 */
	@RequestMapping(value = "/updateOrder",  produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String updateOrder(HttpServletRequest request,
							  @RequestParam(required=false, value="orderID")Long orderID,
							  @RequestParam(required = false, value = "name")String name,
							  @RequestParam(required = false, value = "areaCode")String areaCode,
							  @RequestParam(required = false, value = "phone")String phone,
							  @RequestParam(required = false, value = "overSeasAreaCode")String overSeasAreaCode,
							  @RequestParam(required = false, value = "overSeasPhone")String overSeasPhone,
							  @RequestParam(required = false, value = "age")Integer age,
							  @RequestParam(required = false, value = "cardType")Integer cardType,
							  @RequestParam(required = false, value = "cardNo")String cardNo,
							  @RequestParam(required = false, value = "gender")Integer gender,
							  @RequestParam(required = false, value = "email")String email,
							  @RequestParam(required = false, value = "wechat")String wechat){
		ContextInfo context = this.getContextInfo(request);
		EthUpdateOrderReq updatingReq = new EthUpdateOrderReq();
		updatingReq.setOrderID(orderID);
		//设置乘客信息
		EthPassenger passenger = new EthPassenger();
		passenger.setName(name);
		passenger.setAreaCode(areaCode);
		passenger.setPhone(phone);
		passenger.setOverSeasAreaCode(overSeasAreaCode);
		passenger.setOverSeasPhone(overSeasPhone);
		passenger.setAge(age);
		passenger.setCardType(cardType);
		passenger.setCardNo(cardNo);
		passenger.setGender(gender);
		passenger.setEmail(email);
		passenger.setWechat(wechat);
		
		List<EthPassenger> passengers = new ArrayList<EthPassenger>();
		passengers.add(passenger);
		updatingReq.setPassengers(passengers);
		
		CommonResult cr = check(updatingReq);
		if(!cr.isSuccess()){
			return cr.toJson();
		}
		try {
			CommonResult result = updateOrderService.updating(context, updatingReq);
			return result.toJson();
		} catch (Exception e) {
			log.error("系统错误！", e);
		}
		return CommonResult.makeFail("系统错误！").toJson();

	}
	
	/**
	 * 查询司导(需设置定时器)
	 * 
	 * @author zhang
	 * @param cancelingReq
	 * @return
	 */
	@RequestMapping(value = "/queryDriver",  produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String queryDriver(HttpServletRequest request,
							  @RequestParam(required=false, value="orderID")Long orderID){
		ContextInfo context = this.getContextInfo(request);
		EthQueryDriverReq req = new EthQueryDriverReq();
		req.setOrderID(orderID);
		if(orderID == null){
			return CommonResult.makeFail("订单ID不能为空！").toJson();
		}
		try {
			CommonResult result = queryDriverService.queryDriver(context, req);
			return result.toJson();
		} catch (Exception e) {
			log.error("系统错误！", e);
		}
		return CommonResult.makeFail("系统错误！").toJson();
		
	}
	
	/**
	 * 订单确认(供应商回调接口)
	 * 
	 * @author zhang
	 * @param request
	 * @param orderID
	 * @param yitu8OrderID
	 * @param confirmType
	 * @param message
	 * @return
	 */
	@RequestMapping(value = "/confirmOrder",  produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String confirmOrder(HttpServletRequest request,
							   @RequestParam(required=false, value="orderID")Long orderID,
							   @RequestParam(required=false, value="vendorOrderID")String vendorOrderID,
							   @RequestParam(required=false, value="confirmType")Integer confirmType,
							   @RequestParam(required=false, value="message	")String message	
							   ){
		ContextInfo context = this.getContextInfo(request);
		
		EthConfirmOrderReq req = new EthConfirmOrderReq();
		req.setOrderID(orderID);
		req.setVendorOrderID(vendorOrderID);
		req.setConfirmType(confirmType);
		req.setMessage(message);
		
		CommonResult cr = this.check(req);
		if(!cr.isSuccess()){
			return cr.toJson();
		}
		try {
			CommonResult result = confirmOrderService.confirming(context, req);
			return result.toJson();
		} catch (Exception e) {
			log.error("系统错误！", e);
		}
		return CommonResult.makeFail("系统错误！").toJson();
	}
	
	/**
	 *  司导指派(供应商回调接口)
	 * 
	 * @author zhang
	 * @param request
	 * @param orderID
	 * @param vendorOrderID
	 * @param confirmType
	 * @param driverName
	 * @param driverPhone
	 * @param driverPhone2
	 * @param driverCarName
	 * @param driverWechat
	 * @param driverCarDesc
	 * @param driverCarNo
	 * @return
	 */
	@RequestMapping(value = "/pushDriverInfo",  produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String pushDriverInfo(HttpServletRequest request,
			 					 @RequestParam(required=false, value="orderID")Long orderID,
			 					 @RequestParam(required=false, value="vendorOrderID")String vendorOrderID,
			 					 @RequestParam(required=false, value="confirmType")Integer confirmType,
			 					 @RequestParam(required=false, value="driverName")String driverName,
			 					 @RequestParam(required=false, value="driverPhone")String driverPhone,
			 					 @RequestParam(required=false, value="driverPhone2")String driverPhone2,
			 					 @RequestParam(required=false, value="driverCarName")String driverCarName,
			 					 @RequestParam(required=false, value="driverWechat")String driverWechat,
			 					 @RequestParam(required=false, value="driverCarDesc")String driverCarDesc,
			 					 @RequestParam(required=false, value="driverCarNo")String driverCarNo
								 ){
		ContextInfo context = this.getContextInfo(request);
		EthPushDriverReq req = new EthPushDriverReq();
		req.setOrderID(orderID);
		req.setVendorOrderID(vendorOrderID);
		req.setConfirmType(confirmType);
		
		EthDriver driver = new EthDriver();
		driver.setDriverName(driverName);
		driver.setDriverPhone(driverPhone);
		driver.setDriverPhone(driverPhone2);
		driver.setDriverCarName(driverCarName);
		driver.setDriverCarDesc(driverCarDesc);
		driver.setDriverCarNo(driverCarNo);
		driver.setDriverWechat(driverWechat);
		
		req.setDriver(driver);
		CommonResult cr = this.check(req);
		if(!cr.isSuccess()){
			return cr.toJson();
		}
		try {
			CommonResult result = pushDriverService.pushDriver(context, req);
			return result.toJson();
		} catch (Exception e) {
			log.error("系统错误！", e);
		}
		return CommonResult.makeFail("系统错误！").toJson();
	}
	
	@RequestMapping(value = "/orderFinished",  produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String orderFinished(HttpServletRequest request,
								@RequestParam(required=false, value="orderID")Long orderID,
								@RequestParam(required=false, value="vendorOrderID")String vendorOrderID){
		ContextInfo context = this.getContextInfo(request);
		EthOrderFinishedReq req = new EthOrderFinishedReq();
		req.setOrderID(orderID);
		req.setVendorOrderID(vendorOrderID);
		
		CommonResult cr = this.check(req);
		if(!cr.isSuccess()){
			return cr.toJson();
		}
		try {
			CommonResult result = orderFinishedService.orderFinished(context, req);
			return result.toJson();
		} catch (Exception e) {
			log.error("系统错误！", e);
		}
		return CommonResult.makeFail("系统错误！").toJson();
	}
	
	private CommonResult check(EthOrderFinishedReq req) {
		if(req.getOrderID() == null){
			return CommonResult.makeFail("订单ID不能为空！");
		}
		if(ObjectUtil.noText(req.getVendorOrderID())){
			return CommonResult.makeFail("供应商ID不能为空！");
		}
		return CommonResult.makeSuccess();
	}

	private CommonResult check(EthPushDriverReq req) {
		if(req.getOrderID() == null){
			return CommonResult.makeFail("订单ID不能为空！");
		}
		if(ObjectUtil.noText(req.getVendorOrderID())){
			return CommonResult.makeFail("供应商ID不能为空！");
		}
		if(req.getConfirmType() == null){
			return CommonResult.makeFail("订单确认类型不能为空！");
		}
		if(req.getConfirmType() != 1 || req.getConfirmType() != 2){
			return CommonResult.makeFail("订单确认类型不存在！");
		}
		if(ObjectUtil.noText(req.getDriver().getDriverName())){
			return CommonResult.makeFail("司导姓名不能为空！");
		}
		if(ObjectUtil.noText(req.getDriver().getDriverPhone())){
			return CommonResult.makeFail("司导电话不能为空！");
		}
		return CommonResult.makeSuccess();
	}

	private CommonResult check(EthConfirmOrderReq req) {
		if(req.getOrderID() == null){
			return CommonResult.makeFail("订单ID不能为空！");
		}
		if(ObjectUtil.noText(req.getVendorOrderID())){
			return CommonResult.makeFail("供应商ID不能为空！");
		}
		if(req.getConfirmType() == null){
			return CommonResult.makeFail("订单确认类型不能为空！");
		}
		if(req.getConfirmType() != 1 || req.getConfirmType() != 2){
			return CommonResult.makeFail("订单确认类型不存在！");
		}
		return CommonResult.makeSuccess();
	}

	private CommonResult check(EthUpdateOrderReq req){
		if(req.getOrderID() == null){
			return CommonResult.makeFail("订单ID不能为空！");
		}
		List<EthPassenger> passengers = req.getPassengers();
		if(passengers == null){
			return CommonResult.makeFail("联系人不能为空！");
		}
		for (EthPassenger passenger : passengers) {
			if(ObjectUtil.noText(passenger.getName())){
				return CommonResult.makeFail("联系人姓名不能为空！");
			}
			if(ObjectUtil.noText(passenger.getAreaCode())){
				return CommonResult.makeFail("联系人电话国家代码不能为空！");
			}
			if(ObjectUtil.noText(passenger.getPhone())){
				return CommonResult.makeFail("联系人电话国家代码不能为空！");
			}
		}
		return CommonResult.makeSuccess();
	}
	
	private CommonResult check(EthCancelOrderReq req){
		if(req.getOrderID() == null){
			return CommonResult.makeFail("订单ID不能为空！");
		}
		if(req.getCancelTypeID() == null){
			return CommonResult.makeFail("取消类型不能为空！");
		}
		if(ObjectUtil.noText(req.getCancelReason())){
			return CommonResult.makeFail("取消原因不能为空！");
		}
		return CommonResult.makeSuccess();
	}
	
	private CommonResult check(EthQueryPriceReq  pricingReq){
		if(ObjectUtil.noText(pricingReq.getUseTime())){
			return CommonResult.makeFail("用车时间不能为空！");
		}
		if(!dateStrMatches(pricingReq.getUseTime())){
			return CommonResult.makeFail("用车时间格式不正确！");
		}
		//您至少需要提前12小时以上订车!
		if(!isBefore12Hours(pricingReq.getUseTime())){
			return CommonResult.makeFail("您至少需要提前12小时以上订车！");
		}
		if(pricingReq.getUseDuration() == null){
			return CommonResult.makeFail("用车天数不能为空！");
		}
		if(pricingReq.getProductType() == null){
			return CommonResult.makeFail("产品类型不能为空！");
		}
		if(pricingReq.getProductType() > 4 && pricingReq.getProductType() < 1){
			return CommonResult.makeFail("产品类型不存在！");
		}
		if(pricingReq.getRouteType() == null){
			return CommonResult.makeFail("行程类型不能为空！");
		}
		if(pricingReq.getProductType() > 3 && pricingReq.getProductType() < 1){
			return CommonResult.makeFail("行程类型不存在！");
		}
		//接送机的情况  1或者2
		if(pricingReq.getProductType() == 1 || pricingReq.getProductType() == 2){
			if(ObjectUtil.noText(pricingReq.getAirportCode())){
				return CommonResult.makeFail("机场三字码不能为空！");
			}
		}
		//包车游3，单次接送4
		if(pricingReq.getProductType() == 3 || pricingReq.getProductType() == 4){
			if(ObjectUtil.noText(pricingReq.getFromCityCode())){
				return CommonResult.makeFail("出发城市三字码不能为空！");
			}
		}
		if(pricingReq.getFromCityID() == null){
			return CommonResult.makeFail("出发城市ID不能为空！");
		}
		if(ObjectUtil.noText(pricingReq.getFromAddress())){
			return CommonResult.makeFail("出发地址不能为空！");
		}
		if(pricingReq.getFromLongitude() == null){
			return CommonResult.makeFail("出发地经度不能为空！");
		}
		if(pricingReq.getFromLatitude() == null){
			return CommonResult.makeFail("出发地纬度不能为空！");
		}
		//接机1，送机2 ， 包车游3(跨市包车游情况)，单次接送4
		if(pricingReq.getProductType() == 1 
				|| pricingReq.getProductType() == 2 
				|| pricingReq.getProductType() == 4
				|| (pricingReq.getProductType() == 3 && pricingReq.getRouteType() > 1)){
			if(pricingReq.getToCityID() == null){
				return CommonResult.makeFail("到达城市ID不能为空！");
			}
			if(ObjectUtil.noText(pricingReq.getToAddress())){
				return CommonResult.makeFail("到达地址不能为空！");
			}
			if(pricingReq.getToLongitude() == null){
				return CommonResult.makeFail("到达地经度不能为空！");
			}
			if(pricingReq.getToLatitude() == null){
				return CommonResult.makeFail("到达地纬度不能为空！");
			}
		}
		return CommonResult.makeSuccess();
	}
	
	private CommonResult check(EthSubmitOrderReq request){
		if(ObjectUtil.noText(request.getPriceMark())){
			return CommonResult.makeFail("无此价格标识！");
		}
		if(request.getCarTypeID() == null || request.getCarTypeID() == 0){
			return CommonResult.makeFail("请选择车型！");
		}
		if(request.getStaffNum() == null){
			return CommonResult.makeFail("请填写乘客数量！");
		}
		if(request.getLuggageNum() == null){
			return CommonResult.makeFail("请填写行李数量！");
		}
		if(request.getPassengers() == null ||request.getPassengers().isEmpty()){
			return CommonResult.makeFail("联系人信息不能为空！");
		}
		
		List<EthPassenger> passengers = request.getPassengers();
		if(passengers == null){
			return CommonResult.makeFail("联系人不能为空！");
		}
		for (EthPassenger passenger : passengers) {
			if(ObjectUtil.noText(passenger.getName())){
				return CommonResult.makeFail("联系人姓名不能为空！");
			}
			if(ObjectUtil.noText(passenger.getAreaCode())){
				return CommonResult.makeFail("联系人电话国家代码不能为空！");
			}
			if(ObjectUtil.noText(passenger.getPhone())){
				return CommonResult.makeFail("联系人电话号码不能为空！");
			}
		}
		if(request.getTotalAmount() == null){
			return CommonResult.makeFail("费用总金额不能为空");
		}
		if(request.getSetAmount() == null){
			return CommonResult.makeFail("套餐价格不能为空");
		}
		if(request.getAdditionalServices() !=null){
			for (EthAdditionalService service : request.getAdditionalServices()) {
				if(ObjectUtil.noText(service.getSid())){
					return CommonResult.makeFail("附加服务编码不能为空！");
				}
				if(ObjectUtil.noText(service.getSid())){
					return CommonResult.makeFail("附加服务费不能为空！");
				}
				if(service.getNumber() == null){
					return CommonResult.makeFail("附加服务数量不能为空！");
				}
				if(service.getNumber() == null || service.getNumber() == 0){
					service.setNumber(1);
				}
			}
			if(request.getAdditionalServiceAmount() == null){
				return CommonResult.makeFail("附加服务费不能为空");
			}
		}
		return CommonResult.makeSuccess();
	}
	
	/**
	 * 时间格式匹配
	 * 
	 * @author zhang
	 * @param dateStr
	 * @return
	 */
	private boolean dateStrMatches(String dateStr){
		if(ObjectUtil.noText(dateStr)){
			return false;
		}
		// 正则表达式规则
		String regex = "^((((1[6-9]|[2-9]\\d)\\d{2})-(0[13578]|1[02])-(0[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0[13456789]|1[012])-(0[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-02-(0[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-02-29)) (20|21|22|23|[0-1]\\d):[0-5]\\d:[0-5]\\d$";
		// 编译正则表达式
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(dateStr);
		// 字符串是否与正则表达式相匹配
		return matcher.matches();
	}
	
	/**
	 * 判断用车时间是否比当前系统时间早12小时以上
	 * 
	 * @author zhang
	 * @param useTime
	 * @return
	 */
	private boolean isBefore12Hours(String useTime) {
		try {
			Long useTimeLongs = DateUtil.toLongDate(useTime, "yyyy-MM-dd HH:mm:ss");
			Calendar instance = Calendar.getInstance();
			instance.add(Calendar.HOUR_OF_DAY, 12);
			Date time = instance.getTime();
			Long currentTime = DateUtil.toLongDate(time, "yyyyMMddHHmmss");
			if(useTimeLongs < currentTime){
				return false;
			}
		} catch (Exception e) {
			log.error("时间转换出错！", e);
			return false;
		}
		return true;
	}

}
